package com.thesis.config;

import com.thesis.config.intercepors.AdminLoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfigurer implements WebMvcConfigurer {

    @Autowired
    private AdminLoginInterceptor adminLoginInterceptor;

    // 这个方法是用来配置静态资源的，比如html，js，css，等等
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }

    // 这个方法用来注册拦截器，我们自己写好的拦截器需要通过这里添加注册才能生效
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //后台管理系统拦截器
        registry.addInterceptor(adminLoginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(
                "/admin/login"    //后台管理系统登录页面不拦截
                ,"/user/add"    //用户登录
                ,"/user/registPage"    //用户登录
                ,"/user/checkLogin"    //用户登录
                ,"/receiver/checkLogin"    //用户登录
                , "/admin/logOut" //退出
                , "/admin/checkLogin" //登录检测
                , "/static/**" //静态资源
                , "/common/**" //通用
                , "/app/**" //客户端请求
                , "/home/**" //客户端请求
                , "/" //客户端请求
                , "/wx/**" //小程序端请求
                , "/file/**" //文件请求
                , "/ueditor/**" //文富文本编辑器的请求
                , "/images/**" //图片请求
                , "/wx/record/add" //图片请求
        );
    }
}
